package com.dt.common.validation.parser;

import java.lang.reflect.Field;

import com.alibaba.fastjson.JSONObject;
import com.dt.common.validation.annotation.NotNull;
import com.dt.common.validation.definition.NotNullDefinition;
import com.dt.common.validation.impl.DefaultValidationDefinition;
import com.dt.common.validation.itf.PropertyGetter;

public class NotNullDefinitionParser extends DefinitionParser {

	@Override
	public DefaultValidationDefinition parseFromAnnotation(Field field, PropertyGetter propertyGetter) {
		NotNull notNull = field.getAnnotation(NotNull.class);
		if (notNull != null) {
			NotNullDefinition definition = new NotNullDefinition();
			definition.setRawMsg(notNull.msg());
			return definition;
		}

		return null;
	}

	@Override
	public DefaultValidationDefinition parseFromJson(JSONObject metaValues) {
		NotNullDefinition definition = new NotNullDefinition();
		definition.setRawMsg(this.getMsgDefinition(metaValues, true));
		return definition;
	}

}
